import type { Mark, MarkType } from "@rivet/model";
import type { PatchState } from "@rivet/state";

import { getMarkType } from "./getMarkType.ts";

// 获取标记的属性
export function getMarkAttributes(
  state: PatchState,
  typeOrName: string | MarkType,
): Record<string, any> {
  const type = getMarkType(typeOrName, state.schema);
  const marks: Mark[] = [];

  state.doc.forEach((node) => {
    marks.push(...node.marks);
  });

  const mark = marks.find((markItem) => markItem.type.name === type.name);

  if (!mark) {
    return {};
  }

  return { ...mark.attrs };
}
